'''
https://www.w3.org/TR/did-core/#data-model
https://www.w3.org/TR/did-core/#core-properties
https://www.w3.org/TR/did-core/diagrams/diagram-did-document-entries.svg
Property	Required?	Value constraints
id	: yes	A string that conforms to the rules in § 3.1 DID Syntax.
alsoKnownAs:	no	A set of strings that conform to the rules of [RFC3986] for URIs.
controller:	no	A string or a set of strings that conform to the rules in § 3.1 DID Syntax.
verificationMethod:	no	A set of Verification Method maps that conform to the rules in § Verification Method properties.
authentication:	no	A set of either Verification Method maps that conform to the rules in § Verification Method properties) or strings that conform to the rules in § 3.2 DID URL Syntax.
assertionMethod:	no
keyAgreement:	no
capabilityInvocation:	no
capabilityDelegation:	no
service:	no	A set of Service Endpoint maps that conform to the rules in § Service properties.
'''

from typing import Optional
from pydantic import BaseModel  # 常用的用于数据接口schema定义与检查的库 （https://blog.csdn.net/codename_cys/article/details/107675748）

did_context = ["https://www.w3.org/ns/did/v1"]
did_security_context = ["https://www.w3.org/ns/did/v1", "https://w3id.org/security/suites/ed25519-2020/v1"]


'''
Service properties
Property	Required?	Value constraints
id	yes	A string that conforms to the rules of [RFC3986] for URIs.
type	yes	A string or a set of strings.
serviceEndpoint	yes	A string that conforms to the rules of [RFC3986] for URIs, a map, or a set composed of a one or more strings that conform to the rules of [RFC3986] for URIs and/or maps.
https://www.w3.org/TR/did-core/#service-properties
'''


class DIDDocService(BaseModel):
    id: Optional[str]
    # The value of the type property MUST be a string or a set of strings.
    type: Optional[object]
    # The value of the serviceEndpoint property MUST be a string, a map, or a set composed of one or more strings and/or maps.
    serviceEndpoint: Optional[object]


'''
DOCVerificationMethod Properties
Property	Required?	Value constraints
id	yes	A string that conforms to the rules in § 3.2 DID URL Syntax.
controller	yes	A string that conforms to the rules in § 3.1 DID Syntax.
type	yes	A string.
publicKeyJwk	no	A map representing a JSON Web Key that conforms to [RFC7517]. See definition of publicKeyJwk for additional constraints.
publicKeyMultibase	no
https://www.w3.org/TR/did-core/#verification-method-properties
'''


class DIDDocVerificationMethod(BaseModel):
    id: Optional[str]
    controller: Optional[object]  # controller有可能是单个字符串或者一个数组，所以得泛型
    type: Optional[str]
    publicKeyMultibase: Optional[str]
    publicKeyJwk: Optional[object]  # A map representing a JSON Web Key
    # JwK eg:{'crv': 'Ed25519', 'x': 'VCpo2LMLhn6iWku8MKvSLg2ZAoC-nlOyPVQaO3FxVeQ', 'kty': 'OKP', 'kid': '_Qq0UL2Fq651Q0Fjd6TvnYE-faHiOpRlPVQcY_-tA4A'}


# https://www.w3.org/TR/did-core/#did-document-properties
# 以下连接可以看到全面的sample，有些属性被标记为deprecated
# https://www.w3.org/TR/did-spec-registries/
class DIDDocument(BaseModel):
    #context: Optional[str] = [str("https://www.w3.org/ns/did/v1"),str("https://w3id.org/security/suites/ed25519-2020/v1")]
    id: Optional[str]
    alsoKnownAs: Optional[list[str]]  # A set of strings that conform to the rules of [RFC3986] for URIs.
    controller: Optional[object]  # A string or a set of strings that conform to the rules in 3.1 DID Syntax.
    # A set of Verification Method maps that conform to the rules in Verification Method properties.
    verificationMethod: Optional[list[DIDDocVerificationMethod]]
    # A set of either Verification Method maps that conform to the rules in Verification Method properties) or strings that conform to the rules in 3.2 DID URL Syntax.
    authentication: Optional[list[object]]  # a set of one or more verification methods or strings
    assertionMethod: Optional[list[object]]  # a set of one or more verification methods or strings
    keyAgreement: Optional[list[object]]  # a set of one or more verification methods or strings
    capabilityInvocation: Optional[list[object]]  # a set of one or more verification methods or strings.
    capabilityDelegation: Optional[list[object]]  # a set of one or more verification methods or strings.
    # A set of Service Endpoint maps that conform to the rules in Service properties.
    service: Optional[list[DIDDocService]]
